package com.cyber.app_container.entity;

import jakarta.persistence.*;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(
        uniqueConstraints = {
                @UniqueConstraint(name = "uk_user_name", columnNames = "user_name"),
                @UniqueConstraint(name = "uk_email", columnNames = "email"),
                @UniqueConstraint(name = "uk_phone_number", columnNames = "phone_number")
        },
        indexes = {
                @Index(name = "idx_user_name", columnList = "user_name")
        })
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, columnDefinition = "BIGINT UNSIGNED")
    private Long id;

    @NotBlank(message = "U400001")
    @Size(min = 3, max = 20, message = "U400003")
    @Column(name = "user_name", nullable = false, length = 50)
    private String userName;

    @NotBlank(message = "U400002")
    @Column(name = "password", nullable = false)
    private String password;

    @Email(message = "U400005")
    @NotBlank(message = "U400004")
    @Column(name = "email", nullable = false, length = 100)
    private String email;

    @Column(name = "nick_name", length = 50)
    private String nickName;

    @Column(name = "phone_number", length = 20)
    private String phoneNumber;

    @CreationTimestamp
    @Column(name = "created_at", nullable = false, updatable = false)
    private LocalDateTime createdAt;

    @UpdateTimestamp
    @Column(name = "updated_at", nullable = false)
    private LocalDateTime updatedAt;
}